package cc.cc4414.cc02.chat.controller;

import javax.validation.constraints.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cc.cc4414.cc02.chat.constant.ChatRegexpConsts;
import cc.cc4414.cc02.chat.service.GroupService;
import cc.cc4414.cc02.core.controller.BaseController;
import cc.cc4414.cc02.core.result.ResultVO;
import cc.cc4414.cc02.system.entity.User;

/**
 * @author cc 2018年8月17日
 */
@Validated
@RestController
@RequestMapping("/group")
public class GroupController extends BaseController {

	@Autowired
	private GroupService groupService;

	/**
	 * 创建群组
	 * 
	 * @param groupName
	 *            群名称
	 * @return 是否创建成功
	 */
	@PostMapping("create")
	public ResultVO<Object> create(@Pattern(regexp = ChatRegexpConsts.GROUPNAME) @RequestParam String groupName) {
		User user = getUser();
		groupService.save(groupName, user.getId(), user.getNickname());
		return new ResultVO<>();
	}

}
